package furnitures.parts 
{
	import flash.geom.Point;
	import utils.ArrayUtil;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class FaceBox extends BasePart
	{
		public var posRD:Point;
		//public var handle:Handle;
		public var handles:Vector.<Handle>;
		public var glass:Array = null;
		
		public var sizeType:String="";
		
		public var doorShape:Array;
		
		public var allowExtra:Boolean;
		
		/**
		 * Glass, grid
		 */
		public var extraShape:Array = null;
		
		public var type:String;
		
		/**
		 * линии для отрисовки дверей
		 * прямая [x1, y1, x2, y2]
		 * кривая Безье 2-го порядка [xStart, yStart, xEnd, yEnd, xControl, yControl]
		 */
		public var lines:Array;
		
		
		public static const TYPE_TECH:String = "tech";
		public static const TYPE_FURNITURE:String = "furniture";
		
		public function FaceBox(pos:Point, positionRD:Point, boxType:String = TYPE_FURNITURE) 
		{
			super(pos);
			type = boxType;
			posRD = positionRD;
			allowExtra = true;
		}
		
		public function clone():FaceBox
		{
			var posRDClone:Point = null;
			var i:int;
			
			if (posRD != null)
			{
				posRDClone = posRD.clone();
			}
			var posUVClone:Point;
			if (positionUV != null)
			{
				posUVClone = positionUV.clone();
			}
			var boxClone:FaceBox = new FaceBox(posUVClone, posRDClone);
			if (glass != null)
			{
				boxClone.glass = [];
				for (i = 0; i < glass.length; i++)
				{
					boxClone.glass.push(glass[i]);
				}
			}
			
			/*if (handle != null)
			{
				BoxClone.handle = handle.clone();
			}*/
			
			if (lines != null)
			{
				/*boxClone.lines = [];
				var pointsXY:Array;
				var pointsXYClone:Array;
				for (i = 0; i < lines.length; i++)
				{
					pointsXY = lines[i];
					pointsXYClone = [];
					for (var j:int = 0; j < pointsXY.length; j++)
					{
						pointsXYClone.push(pointsXY[j]);
						//log(i + ", " + j + " = " + pointsXY[j]);
					}
					boxClone.lines.push(pointsXYClone);
				}*/
				boxClone.lines = ArrayUtil.cloneShapeArray(lines);
				
			}
			
			if (doorShape != null) {
				boxClone.doorShape = ArrayUtil.cloneShapeArray(doorShape);
			}
			
			if (extraShape != null) {
				boxClone.extraShape = ArrayUtil.cloneShapeArray(boxClone.extraShape);
			}
			
			if (handles != null)
			{
				for each(var handle:Handle in handles)
				{
					boxClone.addHandle(handle.clone());
				}
			}
			
			boxClone.sizeType = sizeType;
			boxClone.type = this.type;
			boxClone.allowExtra = allowExtra;
			
			return boxClone;
		}
		
		public function addHandle(handle:Handle):void
		{
			if (handles == null)
			{
				handles = new Vector.<Handle>();
			}
			handles.push(handle);
		}
		
	}

}